package model.core;

import model.item.InventoryItem;
import utility.BidirectionalMap;

public class ItemsLibrary {
	private BidirectionalMap<String, InventoryItem> library = new BidirectionalMap<String, InventoryItem>();
	
	private static ItemsLibrary itemsLibrary = null;
	
	private ItemsLibrary(){
		
	}
	
	public static ItemsLibrary getInstance(){
		if (itemsLibrary == null){
			itemsLibrary = new ItemsLibrary();
		}
		return itemsLibrary;
	}
	
	public InventoryItem getItem(String name){
		try {
			return library.getFromSecondSet(name).clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return library.getFromSecondSet(name);
	}
	
	public String getName(InventoryItem item){
		return library.getFromFirstSet(item);
	}
	
	public void put(String name, InventoryItem item){
		library.put(name, item);
	}
}
